package com.yunchang.springboot.scheduled.amazon.mws.report.common;

import com.amazonaws.mws.model.*;
import com.amazonservices.mws.client.MwsUtl;
import com.yunchang.springboot.mapper.log.LogReportRecordMapper;
import com.yunchang.springboot.mapper.mwsreport.MwsDataGetErrorRecordMapper;
import com.yunchang.springboot.mapper.shop.AreaMapper;
import com.yunchang.springboot.mapper.shop.ShopAreaMapper;
import com.yunchang.springboot.mapper.shop.ShopMapper;
import com.yunchang.springboot.models.Area;
import com.yunchang.springboot.models.Shop;
import com.yunchang.springboot.models.dto.shoparea.ShopIdAndAreaIdDto;
import com.yunchang.springboot.models.mwsreportbean.MwsDataGetErrorRecord;
import com.yunchang.springboot.utils.CryptoUtil;
import com.yunchang.springboot.utils.DateUtil;
import com.yunchang.springboot.utils.StringUtil;
import com.yunchang.springboot.utils.databaseutils.DatabaseUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import static com.yunchang.springboot.utils.DateUtil.*;
import static com.yunchang.springboot.utils.DateUtil.dateToLocalDateTime;

/**
 * Amazon mws report获取报告基础信息及方法父类
 *
 * @author czw
 */
@Slf4j
@Service
public class BaseMwsReport {

    /**
     * ReportProcessingStatus状态值
     */
    protected String SUBMITTED = "_SUBMITTED_";
    /**
     * ReportProcessingStatus状态值
     */
    protected String IN_PROGRESS = "_IN_PROGRESS_";
    /**
     * ReportProcessingStatus状态值
     */
    protected String CANCELLED = "_CANCELLED_";
    /**
     * ReportProcessingStatus状态值
     */
    protected String DONE = "_DONE_";
    /**
     * ReportProcessingStatus状态值
     */
    protected String DONE_NO_DATA = "_DONE_NO_DATA_";

    /**
     * 构造MarketplaceWebService的参数（固定值）
     */
    protected String APP_NAME = "AmazonJavascriptScratchpad";

    /**
     * 构造MarketplaceWebService的参数（固定值）
     */
    protected String APP_VERSION = "1.0";

    /**
     * 全部站点都下载的任务名称
     */
    protected final List<String> TASK_NAME_SUBSCRIPTIONS_ALL_AREA = Arrays.asList("payment", "预留库存", "管理亚马逊库存", "库龄", "费用预览", "在售商品报告");

    /**
     * North America region 北美地区
     */
    protected final List<String> NORTH_AMERICA_REGION = Arrays.asList("BR", "CA", "MX", "US");

    /**
     * Europe region 欧洲地区
     */
    protected final List<String> EUROPE_REGION = Arrays.asList("AE", "DE", "EG", "ES", "FR", "GB", "IN", "IT", "SA", "TR");

    /**
     * Far East region 远东地区
     */
    protected final List<String> FAR_EAST_REGION = Arrays.asList("SG", "AU", "JP");

    /**
     * 北美地区代表区域
     */
    protected final String NORTH_AMERICA_REGION_REPRESENTATIVE = "US";

    /**
     * 欧洲地区代表区域
     */
    protected final String EUROPE_REGION_REPRESENTATIVE = "DE";

    /**
     * 远东地区代表区域
     */
    protected final String FAR_EAST_REGION_REPRESENTATIVE = "JP";

    /**
     * 由于日本地区的表头和其他区域不同所以需要区分
     */
    protected final String ESPECIALLY_AREA = "JP";

    /**
     * 墨西哥区域代码
     * 因为墨西哥区域不支持订阅功能，需要单独处理
     */
    protected final String MX_AREA = "MX";

    /**
     * 店铺区域关联表Mapper
     */
    public ShopAreaMapper shopAreaMapper;

    @Autowired
    public void setShopAreaMapper(ShopAreaMapper shopAreaMapper) {
        this.shopAreaMapper = shopAreaMapper;
    }

    /**
     * 店铺表mapper
     */
    public ShopMapper shopMapper;

    @Autowired
    public void setShopMapper(ShopMapper shopMapper) {
        this.shopMapper = shopMapper;
    }

    /**
     * 区域表mapper
     */
    public AreaMapper areaMapper;

    @Autowired
    public void setAreaMapper(AreaMapper areaMapper) {
        this.areaMapper = areaMapper;
    }

    /**
     * 错误日志记录
     */
    private MwsDataGetErrorRecordMapper mwsDataGetErrorRecordMapper;

    @Autowired
    public void setMwsDataGetErrorRecordMapper(MwsDataGetErrorRecordMapper mwsDataGetErrorRecordMapper) {
        this.mwsDataGetErrorRecordMapper = mwsDataGetErrorRecordMapper;
    }

    /**
     * 获取报告日志记录
     */
    public LogReportRecordMapper logReportRecordMapper;

    @Autowired
    public void setLogReportRecordMapper(LogReportRecordMapper logReportRecordMapper) {
        this.logReportRecordMapper = logReportRecordMapper;
    }

    /**
     * 基础报告信息表中的getReportArea标识是大区标识的值
     */
    static final Integer GET_REPORT_AREA_IS_REGION = 1;

    /**
     * 基础报告信息表中的getReportArea标识是所有区域标识的值
     */
    static final Integer GET_REPORT_AREA_IS_ALL_AREA = 2;

    /**
     * 数据库基础信息表
     */
    @Resource
    public DatabaseUtil databaseUtil;


    /**
     * 根据任务名称获取店铺及区域名
     *
     * @param taskName
     */
    public List<Map<Shop, Area>> getShopNameAndAreaByTaskName(String taskName) {
        List<Map<Shop, Area>> shopAndAreaMapList = new ArrayList<>();
        List<Shop> shopList = shopMapper.getAllList();
        for (Shop shop : shopList) {
            Map<Shop, Area> shopAndAreaMap = new ConcurrentHashMap<>();
            Long shopId = shop.getId();
            String sellerId = shop.getSellerId();
            if (StringUtil.isBlank(sellerId)) {
                log.warn("没有查询到sellerId信息，请检查shopId为" + shopId + "的sellerId信息是否正确");
            }
            String mwsAuthToken = shop.getMwsAuthToken();
            if (StringUtil.isBlank(mwsAuthToken)) {
                log.warn("没有查询到mwsAuthToken信息，请检查shopId为" + shopId + "的mwsAuthToken信息是否正确");
            }
            String awsAccessKeyId = shop.getAwsAccessKeyId();
            if (StringUtil.isBlank(awsAccessKeyId)) {
                log.warn("没有查询到awsAccessKeyId信息，请检查shopId为" + shopId + "的awsAccessKeyId信息是否正确");
            }
            String secretKey = shop.getSecretKey();
            if (StringUtil.isBlank(secretKey)) {
                log.warn("没有查询到secretKey信息，请检查shopId为" + shopId + "的secretKey信息是否正确");
            }
            List<Area> areaListByShopId = shopAreaMapper.getAreaListByShopIdExcludeEU(shopId);
            for (Area area : areaListByShopId) {
                if (StringUtil.isBlank(area.getMwsEndPoint())) {
                    log.warn("没有查询到区域名为" + area.getAreaName() + "区域亚马逊MWS 端点，请检查shopId为" + shopId + "的区域信息以及区域详情是否正确");
                }
                if (StringUtil.isBlank(area.getMwsCountryCode())) {
                    log.warn("没有查询到区域名为" + area.getAreaName() + "区域国家代码，请检查shopId为" + shopId + "的区域信息以及区域详情是否正确");
                }
                if (StringUtil.isBlank(area.getMarketplaceId())) {
                    log.warn("没有查询到区域名为" + area.getAreaName() + "区域MarketplaceId，请检查shopId为" + shopId + "的区域信息以及区域详情是否正确");
                }
            }
            shop.setSecretKey(CryptoUtil.decode(shop.getSecretKey()));
            shop.setAwsAccessKeyId(CryptoUtil.decode(shop.getAwsAccessKeyId()));
            shop.setMwsAuthToken(CryptoUtil.decode(shop.getMwsAuthToken()));
            shop.setSellerId(CryptoUtil.decode(shop.getSellerId()));
            // 根据任务名判断是否需要对区域进行处理
            if (!TASK_NAME_SUBSCRIPTIONS_ALL_AREA.contains(taskName)) {
                List<String> allMWSCountryCodeList = new ArrayList<>();
                for (Area area : areaListByShopId) {
                    String MWSCountryCode = area.getMwsCountryCode();
                    if (NORTH_AMERICA_REGION.contains(MWSCountryCode)) {
                        allMWSCountryCodeList.add(NORTH_AMERICA_REGION_REPRESENTATIVE);
                    } else if (EUROPE_REGION.contains(MWSCountryCode)) {
                        allMWSCountryCodeList.add(EUROPE_REGION_REPRESENTATIVE);
                    } else if (FAR_EAST_REGION.contains(MWSCountryCode)) {
                        allMWSCountryCodeList.add(FAR_EAST_REGION_REPRESENTATIVE);
                    } else {
                        log.error("出现未知区域：" + MWSCountryCode);
                    }
                }
                // 对重复的区域进行去重
                LinkedList<String> onlyMWSCountryCodeList = new LinkedList<>();
                Iterator<String> it = allMWSCountryCodeList.iterator();
                while (it.hasNext()) {
                    String str = it.next();
                    if (!onlyMWSCountryCodeList.contains(str)) {
                        onlyMWSCountryCodeList.add(str);
                    }
                }
                // 将mwsCountryCode转换为area对象
                for (String mwsCountryCode : onlyMWSCountryCodeList) {
                    Area area = areaMapper.getAreaByMWSCountryCode(mwsCountryCode);
                    shopAndAreaMap.put(shop, area);
                    shopAndAreaMapList.add(shopAndAreaMap);
                }
            } else {
                for (Area area : areaListByShopId) {
                    shopAndAreaMapList.add(new HashMap<Shop, Area>(1) {{
                        put(shop, area);
                    }});
                }
            }
        }
        return shopAndAreaMapList;
    }


    /**
     * 打印出错信息
     *
     * @param taskName
     * @param shopName
     * @param areaCountryCode
     * @param errorMsg
     */
    @Async
    protected void logWarnErrorMsg(String taskName, String shopName, String areaCountryCode, StringBuffer errorMsg) {
        log.warn("↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓定时任务出错↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓");
        log.warn("×××××" + taskName + "×××定时任务出错×××" +
                "---店铺名称:" + shopName +
                "---区域国家代码:" + areaCountryCode +
                "×××××错误详情:" + errorMsg);
        log.warn("↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑定时任务出错↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑");
        MwsDataGetErrorRecord record = new MwsDataGetErrorRecord();
        record.setShop(shopName);
        record.setArea(areaCountryCode);
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        Date date = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format1 = format.format(date);
        record.setDate(format1);
        //是否处理，0:未处理,1:已处理',
        record.setIsHandle(0);
        //类型:亚马逊MwsApi定时任务
        record.setName(taskName);
        record.setRemark("亚马逊MwsApi定时任务出错,任务名称:" + taskName
                + "出错的时间:" + format1
                + "错误详情:" + errorMsg);
        record.setCreateTime(DateUtil.getFutureDateTime(0));
        record.setType(1);
        mwsDataGetErrorRecordMapper.insertSelective(record);
    }

    /**
     * 根据reportInfo获取对应的店铺和区域信息
     *
     * @param reportInfoId
     * @return
     */
    public List<Map<Shop, Area>> getShopAndAreaInfoByReportInfoId(Integer reportInfoId) {
        List<ShopIdAndAreaIdDto> shopIdAndAreaIdDtoList = shopAreaMapper.selectShopIdAndAreaIdByReportInfoId(reportInfoId);
        List<Map<Shop, Area>> shopAndAreaMapList = new ArrayList<>();
        if (null != shopIdAndAreaIdDtoList && !shopIdAndAreaIdDtoList.isEmpty()) {
            for (ShopIdAndAreaIdDto shopIdAndAreaIdDto : shopIdAndAreaIdDtoList) {
                Shop shop = shopMapper.selectByShopId(shopIdAndAreaIdDto.getShopId());
                shop.setSellerId(CryptoUtil.decode(shop.getSellerId()));
                shop.setMwsAuthToken(CryptoUtil.decode(shop.getMwsAuthToken()));
                shop.setAwsAccessKeyId(CryptoUtil.decode(shop.getAwsAccessKeyId()));
                shop.setSecretKey(CryptoUtil.decode(shop.getSecretKey()));
                shopAndAreaMapList.add(new HashMap<Shop, Area>(1) {{
                    put(shop, areaMapper.selectByAreaId(shopIdAndAreaIdDto.getAreaId()));
                }});
            }
        }
        return shopAndAreaMapList;
    }

    /**
     * 根据报告基础信息表中的getReportArea字段获取对应的店铺及区域
     *
     * @param getReportArea
     */
    public List<Map<Shop, Area>> getShopAndAreaInfoByGetReportArea(Integer getReportArea) {
        List<Shop> shopList = shopMapper.selectAllShop();
        List<Map<Shop, Area>> shopAndAreaMapList = new ArrayList<>();
        if (null != getReportArea) {
            if (getReportArea.equals(GET_REPORT_AREA_IS_REGION)) {
                if (null != shopList && !shopList.isEmpty()) {
                    for (Shop shopFor : shopList) {
                        shopFor.setSellerId(CryptoUtil.decode(shopFor.getSellerId()));
                        shopFor.setMwsAuthToken(CryptoUtil.decode(shopFor.getMwsAuthToken()));
                        shopFor.setAwsAccessKeyId(CryptoUtil.decode(shopFor.getAwsAccessKeyId()));
                        shopFor.setSecretKey(CryptoUtil.decode(shopFor.getSecretKey()));
                        List<Area> areaList = areaMapper.selectByShopIdGroupByRegionCode(shopFor.getId());
                        for (Area areaFor : areaList) {
                            shopAndAreaMapList.add(new HashMap<Shop, Area>(1) {{
                                put(shopFor, areaFor);
                            }});
                        }
                    }
                }
            }
            if (getReportArea.equals(GET_REPORT_AREA_IS_ALL_AREA)) {
                if (null != shopList && !shopList.isEmpty()) {
                    for (Shop shopFor : shopList) {
                        shopFor.setSellerId(CryptoUtil.decode(shopFor.getSellerId()));
                        shopFor.setMwsAuthToken(CryptoUtil.decode(shopFor.getMwsAuthToken()));
                        shopFor.setAwsAccessKeyId(CryptoUtil.decode(shopFor.getAwsAccessKeyId()));
                        shopFor.setSecretKey(CryptoUtil.decode(shopFor.getSecretKey()));
                        List<Area> areaList = areaMapper.selectByShopId(shopFor.getId());
                        for (Area areaFor : areaList) {
                            shopAndAreaMapList.add(new HashMap<Shop, Area>(1) {{
                                put(shopFor, areaFor);
                            }});
                        }
                    }
                }
            }
        }
        return shopAndAreaMapList;
    }

    /**
     * 根据报告的时间范围获取下载报告的开始时间和结束时间
     *
     * @param timeScope
     * @return 返回key 值为 reportBeginTime（下载报告的开始时间）和reportEndTime（下载报告的结束时间） XMLGregorianCalendar（时间类型）
     */
    public Map<String, XMLGregorianCalendar> getReportTimeScope(String timeScope) {
        Map<String, XMLGregorianCalendar> reportTimeMap = new HashMap<>(2);
        if (!StringUtils.isEmpty(timeScope)) {
            XMLGregorianCalendar reportBeginTime = MwsUtl.getDTF().newXMLGregorianCalendar();
            XMLGregorianCalendar reportEndTime = MwsUtl.getDTF().newXMLGregorianCalendar();
            switch (timeScope) {
                case "daily":
                    LocalDateTime localDateTimeDaily = dateToLocalDateTime(getFutureDateDay(-2));
                    reportBeginTime.setYear(localDateTimeDaily.getYear());
                    reportBeginTime.setMonth(localDateTimeDaily.getMonthValue());
                    reportBeginTime.setDay(localDateTimeDaily.getDayOfMonth());
                    reportBeginTime.setTime(localDateTimeDaily.getHour(), localDateTimeDaily.getMinute(), localDateTimeDaily.getSecond());
                    localDateTimeDaily = dateToLocalDateTime(getFutureDateDayLastTime(-2));
                    reportEndTime.setYear(localDateTimeDaily.getYear());
                    reportEndTime.setMonth(localDateTimeDaily.getMonthValue());
                    reportEndTime.setDay(localDateTimeDaily.getDayOfMonth());
                    reportEndTime.setTime(localDateTimeDaily.getHour(), localDateTimeDaily.getMinute(), localDateTimeDaily.getSecond());
                    reportTimeMap.put("reportBeginTime", reportBeginTime);
                    reportTimeMap.put("reportEndTime", reportEndTime);
                    break;
                case "realTime":
                    LocalDateTime localDateTimeRealTime = dateToLocalDateTime(getFutureDateDay(0));
                    reportBeginTime.setYear(localDateTimeRealTime.getYear());
                    reportBeginTime.setMonth(localDateTimeRealTime.getMonthValue());
                    reportBeginTime.setDay(localDateTimeRealTime.getDayOfMonth());
                    reportBeginTime.setTime(localDateTimeRealTime.getHour(), localDateTimeRealTime.getMinute(), localDateTimeRealTime.getSecond());
                    localDateTimeRealTime = dateToLocalDateTime(getFutureDateDayLastTime(0));
                    reportEndTime.setYear(localDateTimeRealTime.getYear());
                    reportEndTime.setMonth(localDateTimeRealTime.getMonthValue());
                    reportEndTime.setDay(localDateTimeRealTime.getDayOfMonth());
                    reportEndTime.setTime(localDateTimeRealTime.getHour(), localDateTimeRealTime.getMinute(), localDateTimeRealTime.getSecond());
                    reportTimeMap.put("reportBeginTime", reportBeginTime);
                    reportTimeMap.put("reportEndTime", reportEndTime);
                    break;
                case "monthly":
                    LocalDateTime localDateTimeMonthly = dateToLocalDateTime(DateUtil.getMonthFirstDayByDate(new Date(), -1));
                    reportBeginTime.setYear(localDateTimeMonthly.getYear());
                    reportBeginTime.setMonth(localDateTimeMonthly.getMonthValue());
                    reportBeginTime.setDay(localDateTimeMonthly.getDayOfMonth());
                    reportBeginTime.setTime(localDateTimeMonthly.getHour(), localDateTimeMonthly.getMinute(), localDateTimeMonthly.getSecond());
                    localDateTimeMonthly = dateToLocalDateTime(DateUtil.getMonthLastDayByDate(new Date(), -1));
                    reportEndTime.setYear(localDateTimeMonthly.getYear());
                    reportEndTime.setMonth(localDateTimeMonthly.getMonthValue());
                    reportEndTime.setDay(localDateTimeMonthly.getDayOfMonth());
                    reportEndTime.setTime(localDateTimeMonthly.getHour(), localDateTimeMonthly.getMinute(), localDateTimeMonthly.getSecond());
                    reportTimeMap.put("reportBeginTime", reportBeginTime);
                    reportTimeMap.put("reportEndTime", reportEndTime);
                    break;
                case "thirtyDays":
                    LocalDateTime localDateTimeThirtyDays = dateToLocalDateTime(DateUtil.getFutureDateDay(-30));
                    reportBeginTime.setYear(localDateTimeThirtyDays.getYear());
                    reportBeginTime.setMonth(localDateTimeThirtyDays.getMonthValue());
                    reportBeginTime.setDay(localDateTimeThirtyDays.getDayOfMonth());
                    reportBeginTime.setTime(localDateTimeThirtyDays.getHour(), localDateTimeThirtyDays.getMinute(), localDateTimeThirtyDays.getSecond());
                    localDateTimeThirtyDays = dateToLocalDateTime(DateUtil.getFutureDateDayLastTime(0));
                    reportEndTime.setYear(localDateTimeThirtyDays.getYear());
                    reportEndTime.setMonth(localDateTimeThirtyDays.getMonthValue());
                    reportEndTime.setDay(localDateTimeThirtyDays.getDayOfMonth());
                    reportEndTime.setTime(localDateTimeThirtyDays.getHour(), localDateTimeThirtyDays.getMinute(), localDateTimeThirtyDays.getSecond());
                    reportTimeMap.put("reportBeginTime", reportBeginTime);
                    reportTimeMap.put("reportEndTime", reportEndTime);
                    break;
            }
        }
        return reportTimeMap;
    }

    /**
     * 根据获取历史报告的时间范围获得下载报告的开始时间和结束时间
     *
     * @param getHistoryTime 获取历史数据的时间范围标识(1: 半年 2：一年 3：一年半 4：两年)
     * @return 返回key 值为 reportBeginTime（下载报告的开始时间）和reportEndTime（下载报告的结束时间） XMLGregorianCalendar（时间类型），多个map放在list集合中
     */
    public List<Map<String, XMLGregorianCalendar>> getReportHistoryTimeScope(Integer getHistoryTime) {
        List<Map<String, XMLGregorianCalendar>> reportTimeScopeList = new ArrayList<>();
        LocalDateTime now = LocalDateTime.now();
        if (getHistoryTime == null) {
            return null;
        }
        switch (getHistoryTime) {
            case 1:
                LocalDateTime endLocalDateTime = now.minusDays(3);
                LocalDateTime startLocalDateTime = now.minusDays(180L);
                setTimeScopeByHistoryTime(startLocalDateTime,endLocalDateTime,now,reportTimeScopeList);
                break;
            case 2:
                endLocalDateTime = now.minusDays(3);
                startLocalDateTime = now.minusDays(360L);
                setTimeScopeByHistoryTime(startLocalDateTime,endLocalDateTime,now,reportTimeScopeList);
                break;
            case 3:
                endLocalDateTime = now.minusDays(3);
                startLocalDateTime = now.minusDays(540L);
                setTimeScopeByHistoryTime(startLocalDateTime,endLocalDateTime,now,reportTimeScopeList);
                break;
            case 4:
                endLocalDateTime = now.minusDays(3);
                startLocalDateTime = now.minusDays(720L);
                setTimeScopeByHistoryTime(startLocalDateTime,endLocalDateTime,now,reportTimeScopeList);
                break;
        }
        return reportTimeScopeList;
    }

    private void setTimeScopeByHistoryTime(LocalDateTime startLocalDateTime,LocalDateTime endLocalDateTime,LocalDateTime now,List<Map<String, XMLGregorianCalendar>> reportTimeScopeList){
        while (startLocalDateTime.isBefore(now)) {
            Map<String, XMLGregorianCalendar> reportTimeMap = new HashMap<>(2);
            XMLGregorianCalendar reportBeginTime = MwsUtl.getDTF().newXMLGregorianCalendar();
            XMLGregorianCalendar reportEndTime = MwsUtl.getDTF().newXMLGregorianCalendar();
            reportBeginTime.setYear(startLocalDateTime.getYear());
            reportBeginTime.setMonth(startLocalDateTime.getMonthValue());
            reportBeginTime.setDay(startLocalDateTime.getDayOfMonth());
            reportBeginTime.setTime(0, 0, 0);
            reportTimeMap.put("reportBeginTime", reportBeginTime);
            startLocalDateTime = startLocalDateTime.minusDays(-60);
            if (startLocalDateTime.isBefore(now)) {
                reportEndTime.setYear(startLocalDateTime.minusDays(1).getYear());
                reportEndTime.setMonth(startLocalDateTime.minusDays(1).getMonthValue());
                reportEndTime.setDay(startLocalDateTime.minusDays(1).getDayOfMonth());
                reportEndTime.setTime(23, 59, 59);
            } else {
                reportEndTime.setYear(endLocalDateTime.getYear());
                reportEndTime.setMonth(endLocalDateTime.getMonthValue());
                reportEndTime.setDay(endLocalDateTime.getDayOfMonth());
                reportEndTime.setTime(23, 59, 59);
            }
            reportTimeMap.put("reportEndTime", reportEndTime);
            reportTimeScopeList.add(reportTimeMap);
        }
    }

    /**
     * 根据getReportRequestListResponse获取ReportProcessingStatus值
     *
     * @param getReportRequestListResponse
     * @return
     */
    public String isReportProcessingStatus(GetReportRequestListResponse getReportRequestListResponse) {
        if (getReportRequestListResponse.isSetGetReportRequestListResult()) {
            GetReportRequestListResult getReportRequestListResult = getReportRequestListResponse.getGetReportRequestListResult();
            java.util.List<ReportRequestInfo> reportRequestInfoList = getReportRequestListResult.getReportRequestInfoList();
            for (ReportRequestInfo reportRequestInfo : reportRequestInfoList) {
                if (reportRequestInfo.isSetReportProcessingStatus()) {
                    return reportRequestInfo.getReportProcessingStatus();
                }
            }
        }
        return null;
    }

    /**
     * 根据getReportRequestListResponse获取GetGeneratedReportId值
     *
     * @param getReportRequestListResponse
     * @return
     */
    public String isGetGeneratedReportId(GetReportRequestListResponse getReportRequestListResponse) {
        if (getReportRequestListResponse.isSetGetReportRequestListResult()) {
            GetReportRequestListResult getReportRequestListResult = getReportRequestListResponse.getGetReportRequestListResult();
            java.util.List<ReportRequestInfo> reportRequestInfoList = getReportRequestListResult.getReportRequestInfoList();
            for (ReportRequestInfo reportRequestInfo : reportRequestInfoList) {
                if (reportRequestInfo.isSetGeneratedReportId()) {
                    return reportRequestInfo.getGeneratedReportId();
                }
            }
        }
        return null;
    }

    /**
     * 通过GetReportList的接口返回对象获取reportId
     *
     * @param getReportListResponse
     * @return
     */
    public String getReportIdBy(GetReportListResponse getReportListResponse) {
        String reportId = null;
        if (getReportListResponse.isSetGetReportListResult()) {
            GetReportListResult getReportListResult = getReportListResponse.getGetReportListResult();
            java.util.List<ReportInfo> reportInfoListList = getReportListResult.getReportInfoList();
            for (ReportInfo reportInfoList : reportInfoListList) {
                reportId = reportInfoList.getReportId();
            }
        }
        return reportId;
    }

    /**
     * 线程等待
     *
     * @param mis
     * @throws InterruptedException
     */
    public void threadNeedSleep(Long mis) throws InterruptedException {
        synchronized (this) {
            this.wait(mis);
        }
    }

}
